<?php
	require_once("../functions.php");
	if(!isLoggedIn()){
		header("location:index.php?message=".urlencode("Please login first."));
		die();
	}
	
	$con = connectToDB();
	
	$uname = $_SESSION["username"];
	$result = mysql_query("select * from user where username = '$uname'",$con);
	$nrows = mysql_num_rows($result);
	
	if($nrows == 1){
		$row = mysql_fetch_array($result);
	}else{
		echo "An error occurred.";
		die();
	}
?>
<link rel="stylesheet" type="text/css" href="lib/dojox/widget/Calendar/Calendar.css" />
<form id="editAccountForm" dojoType="dijit.form.Form" method="post" action="ajax/editaccount_submit.php">
	<div style="border: solid 3px #CBDCED;padding:10px;">
		<h2 style="color:#3366CC">Edit Account </h2>
		<p>Update your account or change password.</p><br />
		<table style="width:100%">
			<tr>
				<td>
					<label for="username">Username</label>
				</td>
				<td>
					<input type="text" id="username" name="username" value="<?php echo $row["username" ]?>" dojoType="dijit.form.ValidationTextBox" required="true">
				</td>
			</tr>
			<tr>
				<td>
					Password
				</td>
				<td>
					Change password <input type="checkbox" id="passwordCheckbox" onclick="changePassword()" />
					<div dojoType="dojox.form.PasswordValidator" name="password" id="passwordValidator" disabled="disabled">
						<table>
							<tr>
								<td><label for="password">Old</label></td>
								<td><input type="password" id="old" dojoType="dijit.form.ValidationTextBox" required="true" name="old"  disabled="disabled" /></td>
							</tr>
							<tr>
								<td><label for="new">New</label></td>
								<td><input type="password" id="new" pwType="new" disabled="disabled" /></td>
							</tr>
							<tr>
								<td><label for="confirm">Confirm</label></td>
								<td><input type="password" id="confirm" pwType="verify" disabled="disabled" /></td>
							</tr>
						</table>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="2"><br /><br /></td>
			</tr>
			<tr>
				<td>
					<label for="first">First name</label>
				</td>
				<td>
					<input type="text" id="first" name="first" value="<?php echo $row["first" ]?>" dojoType="dijit.form.ValidationTextBox" required="true" />
				</td>
			</tr>
			<tr>
				<td>
					<label for="last">Last name</label>
				</td>
				<td>
					<input type="text" id="last" name="last" value="<?php echo $row["last" ]?>" dojoType="dijit.form.ValidationTextBox" required="true" />
				</td>
			</tr>
			<tr>
				<td>
					<label for="birthdate">Birthdate</label>
				</td>
				<td>
					<input type="text" id="birthdate" name="birthdate" 
					dojoType="dijit.form.DateTextBox" required="true" 
					style="hidden" popupClass="dojox.widget.Calendar"
					value="<?php echo $row["birthdate" ]?>" 
					/>
				</td>
			</tr>
			<tr>
				<td colspan="2"><br /><br /></td>
			</tr>
			<tr>
				<td>
					<label for="occupation">Occupation</label>
				</td>
				<td>
					<input type="text" id="occupation" name="occupation" value="<?php echo $row["occupation" ]?>" dojoType="dijit.form.ValidationTextBox" />
				</td>
			</tr>
			<tr>
				<td>
					<label for="organization">Organization</label>
				</td>
				<td>
					<input type="text" id="organization" name="organization" value="<?php echo $row["organization" ]?>" dojoType="dijit.form.ValidationTextBox" />
				</td>
			</tr>
		</table>
		<br /><br />
		<p class="center">
			<button label="Submit" dojoType="dijit.form.Button" onclick="editAccountSubmit()" />
		</p>
		<br />
	</div>
</form>
<div style="border: solid 3px #CBDCED;padding:10px;">
	<h2 style="color:#3366CC">Delete This Account </h2>
	<p>
		To deactivate your account, please click the Delete Account button. Note that this will also 
		delete all of your projects.
	</p><br />
	<button value="Delete Account" dojoType="dijit.form.Button" onclick="if(confirm('Are you sure you want to delete your account?')){deleteAccount()}">Delete Account</button> 
</div>
<?php mysql_free_result($result); ?>